﻿Imports System.Text
Imports System.Reflection

Public Class Log

    Public Shared Sub Write(ByVal message As String)
        Try
            Dim Log As New EventLog()
            Log.Source = Assembly.GetExecutingAssembly().FullName()
            Log.WriteEntry(message.ToString(), EventLogEntryType.Warning)
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Write(ByVal text As String, ByVal currentException As Exception)
        Try
            Dim message As New StringBuilder()
            message.AppendLine(text)
            While (currentException IsNot Nothing)
                message.AppendFormat("" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "type={0}" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "message={1}" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "stack=" & Chr(13) & "" & Chr(10) & "{2}" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "", currentException.[GetType]().FullName, currentException.Message, currentException.StackTrace)
                currentException = currentException.InnerException
            End While

            Dim Log As New EventLog()
            Log.Source = Assembly.GetExecutingAssembly().FullName()
            Log.WriteEntry(message.ToString(), EventLogEntryType.[Error])

        Catch ex As Exception
            'Swallow exception nothing much we can do here.
        End Try
    End Sub

End Class
